package com.itheima.d7_methodreference;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 实例方法的引用 对象名::方法名
 */
public class Demo2 {
    public static void main(String[] args) {
        Student[] students = new Student[6];
        students[0] = new Student("殷素素", 35, 50.5, '女');
        students[1] = new Student("杨幂", 28, 48, '女');
        students[2] = new Student("张无忌", 25, 65, '男');
        students[3] = new Student("小昭", 19, 38, '女');
        students[4] = new Student("赵敏", 27, 45, '女');
        students[5] = new Student("刘亦菲", 36, 45, '女');


        //打印数组中的数据
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println(s.getName() + " " + s.getAge() + " " + s.getHeight() + " " + s.getSex());
        }
        System.out.println("--------------------------------------------------------------------------------");


        //实例方法的引用
        //    匿名内部类格式
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getHeight(), o2.getHeight());
            }
        });
        // ⬇⬇ Lambda表达式简写格式
        Arrays.sort(students, (o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight()));
        // ⬇⬇ 方法引用格式
        //创建对象
        Student s = new Student();
        Arrays.sort(students,s::compareByHeight);



        //打印数组中的数据库
        for (int i = 0; i < students.length; i++) {
            Student s2 = students[i];
            System.out.println(s2.getName() + " " + s2.getAge() + " " + s2.getHeight() + " " + s2.getSex());
        }


    }
}
